package org.swqsbssddqs.shortlink.project.service.impl;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.stereotype.Service;
import org.swqsbssddqs.shortlink.project.service.UrlTitleService;

import java.io.IOException;

@Service

public class UrlTitleServiceImpl implements UrlTitleService {

    @Override
    public String getTitleByUrl(String url) {
        Document document = null;
        try {
            document = Jsoup.connect(url).get();
        } catch (IOException e) {
            return "Error while fetching title.";
        }
        return document.title();
    }
}
